package com.java.time;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class Local_Date_Time_API {
    public static void main(String[] args) {
        // now：当前时间Local_Date_Time对象
        System.out.println(LocalDate.now()); // 2024-02-29
        System.out.println(LocalTime.now()); // 13:00:16.536
        System.out.println(LocalDateTime.now()); // 2024-02-29T13:00:16.536
        
        // of：指定时间Local_Date_Time对象
        System.out.println(LocalDate.of(2001, 3, 4)); // 2001-03-04
        System.out.println(LocalTime.of(10, 10, 10)); // 10:10:10
        System.out.println(LocalDateTime.of(2001, 3, 4, 10, 10, 10)); // 2001-03-04T10:10:10
        
        // toXxx：LocalDateTime转为LocalDate或LocalTime
        System.out.println(LocalDateTime.now().toLocalDate()); // 2024-02-29
        System.out.println(LocalDateTime.now().toLocalTime()); // 13:00:16.536
        
        // getXxx：获取某日期或时间的值
        System.out.println(LocalDate.now().getYear()); // 2024
        System.out.println(LocalTime.now().getHour()); // 13
        System.out.println(LocalDateTime.now().getMonthValue()); // 2
        System.out.println(LocalDateTime.now().getSecond()); // 16
        
        // isXxx：判断时间的系列方法
        System.out.println(LocalDate.now().isBefore(LocalDate.of(2001, 3, 4))); // false
        System.out.println(LocalTime.now().isAfter(LocalTime.of(10, 10, 10))); // true
        System.out.println(LocalDateTime.now().isAfter(LocalDateTime.of(2001, 3, 4, 10, 10, 10))); // true
        
        // withXxx：修改时间的系列方法
        System.out.println(LocalDate.now().withYear(2001)); // 2001-02-28
        System.out.println(LocalTime.now().withHour(0)); // 00:00:16.537
        System.out.println(LocalDateTime.now().withMonth(4)); // 2024-04-29T13:00:16.537
        
        // plusXxx：增加时间的系列方法
        System.out.println(LocalDate.now().plusYears(2)); // 2026-02-28
        System.out.println(LocalTime.now().plusHours(2)); // 15:00:16.537
        System.out.println(LocalDateTime.now().plusMonths(2)); // 2024-04-29T13:00:16.537
        
        // minusXxx：减少时间的系列方法
        System.out.println(LocalDate.now().minusYears(2)); // 2022-02-28
        System.out.println(LocalTime.now().minusHours(2)); // 11:00:16.537
        System.out.println(LocalDateTime.now().minusMonths(2)); // 2023-12-29T13:00:16.537
    }
}
